﻿@model ThaireInvestmentWeb.Models.FixedIncomeSaleModel
@{
    ViewBag.Title = "INPUT Sale Fixed Income Securities";
}
<script>
    $(document).ready(function () {

        $("#TradeDate,#SettlementDate").datepicker(
      {
          dateFormat: 'dd/mm/yy',
          isBuddhist: true,
          showOn: 'button',
          showAnim: 'fadeIn',
          changeMonth: true,
          changeYear: true,
          showButtonPanel: true,
          buttonImage: '@Url.Content("~/Content/images/Calendar.png")',
          onSelect: function (dateText, inst) {
             
          }
      });


        $("#BtnCancel").click(function (event) {

            //  showConfirm(null, testYes);
            showConfirm("ยกเลิก ?", function ()
            {
                //มาจากหน้าเพิ่ม
                @if (Request["transactionID"]==null)
                {
                     <text>
                        window.location.href = 'EditPurchase?purchaseID=@Model.PurcheseID';
                     </text> 
                }else
                {
                     <text>
                window.location.href = 'EditFixedIncome?fixedincomeID=@Model.HeaderID';
                     </text> 
                }
            });
            return false;
        });


        $("#CleanPrice").change(calGrossPrice);
        $("#AI").change(calGrossPrice);


    });

    function calGrossPrice() {

        var p1 = $("#CleanPrice").val();
        var p2 = $("#AI").val();
        if (p1 != '' && p2 != '') {
            var payValue = parseDouble(p1) + parseDouble(p2);
            $('#GrossPrice').val(FormatNumber5(payValue));
         
        }
    }

    $('CancelBtn').click(function (event) 
    {
       
        if (confirm("ยกเลิก ?"))
        {
            window.location.href= '@Url.Action("EditFixedIncome", "FixedIncome", new { fixedincomeID = @Model.HeaderID })';
        }else
        {
            event.preventDefault();
            return false;
        }

    });

    $('BtnSave').click(function (event) 
    {
        var isValid = $('#mainForm').valid();
        if(isValid)
        {
            if (!confirm("ยืนยันการบันทึก"))
            {
                event.preventDefault();
            }
        }else
        {
                   
            event.preventDefault();
        }
    });
</script>
<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">Instrument Type > <a href="fixedIncomeList">Fixed Income List</a>> <a href="ManageFixedIncomeSecurittes">Header </a>> <a href="AddFixedIncomePurchase">Purchase </a>> Sale </div>
        </td>
    </tr>
</table>

<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">INPUT Sale Fixed Income Securities</td>
    </tr>
</table>

<table width="951" border="0" align="center">
    <tr>
        <td>@Html.ValidationSummary(true)</td>
    </tr>
    <tr>
        <td>

            <table width="100%" border="0" align="center" cellspacing="2">
                <!--DWLayoutTable-->
                <tr>
                    <td width="551" height="31">&nbsp;</td>
                    <td width="236" valign="top">
                        <div align="right">Create by :</div>
                    </td>
                    <td width="10">&nbsp;</td>
                    <td width="139">Create Time</td>
                </tr>
                <tr>
                    <td height="31">&nbsp;</td>
                    <td>
                        <div align="right">Update by : </div>
                    </td>
                    <td>&nbsp;</td>
                    <td>Update Time</td>
                </tr>
            </table>
            @Html.Partial("_FixedIncomeHeaderView", Model.PurchaseModel)

              <div>&nbsp;</div>

            @Html.Partial("_FixedIncomePurchaseView", Model.PurchaseModel)


            @using (Html.BeginForm("FixedIncomeSaleFormAction", "FixedIncome", FormMethod.Post, new { id = "mainForm" }))
            {
                <table width="100%" border="0" align="center" cellspacing="2">

                    <tr>
                        <td style="width: 239px">
                            <div align="right">ประเภทธุรกรรม: </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>
                        <td width="260">
                            @Html.TextBoxFor(model => model.TransactionType, new { @readonly = "readonly" })


                        </td>
                        <td align="right" style="width: 164px">&nbsp;</td>
                        <td width="6">&nbsp;</td>
                        <td width="223">&nbsp;</td>
                    </tr>
                    <tr>
                        <td style="width: 239px">
                            <div align="right">Trade Date <span class="error">*</span>    : </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>

                        <td>@Html.TextBoxFor(model => model.TradeDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(Model.TradeDate)  })   @Html.ValidationMessageFor(model => model.TradeDate)</td>
                        <td style="width: 164px">
                            <div align="right">Settlement Date <span class="error">*</span> : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.SettlementDate, new { @readonly = "readonly", @Value =  ThaireInvestmentWeb.Util.WebUtil.FormatDate(Model.SettlementDate)  }) @Html.ValidationMessageFor(model => model.SettlementDate)</td>
                    </tr>
                    <tr>
                        <td style="width: 239px">
                            <div align="right">Unit <span class="error">*</span>    : </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.Unit, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Unit)})   @Html.ValidationMessageFor(model => model.Unit)</td>
                        <td style="width: 164px">
                            <div align="right">Yield <span class="error">*</span> : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.Yield, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.Yield) }) @Html.ValidationMessageFor(model => model.Yield)</td>
                    </tr>
                    <tr>
                        <td style="width: 239px">
                            <div align="right">Counter party <span class="error">*</span>  : </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>
                        <td>@Html.DropDownListFor(model => model.SelectedCounterParty, Model.CounterPartyList) @Html.ValidationMessageFor(model => model.SelectedCounterParty)</td>
                        <td style="width: 164px">
                            <div align="right">Clean Price <span class="error">*</span> :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.CleanPrice, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.CleanPrice)})</td>
                    </tr>
                    <tr>
                        <td style="width: 239px">
                            <div align="right">Type of Payment <span class="error">*</span>   : </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>
                        <td>@Html.DropDownListFor(model => model.SelectedTypeOfPayment, Model.TypeOfPayment) @Html.ValidationMessageFor(model => model.SelectedTypeOfPayment)</td>
                        <td style="width: 164px">
                            <div align="right">AI :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.AI, new { @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.AI)})  @Html.ValidationMessageFor(model => model.AI)</td>
                    </tr>
                    <tr>
                        <td style="width: 239px">
                            <div align="right">Ref. No.  <span class="error">* </span>: </div>
                        </td>
                        <td style="width: 9px">&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.RefNo) @Html.ValidationMessageFor(model => model.RefNo)</td>
                        <td style="width: 164px">
                            <div align="right">Gross Price :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td>@Html.TextBoxFor(model => model.GrossPrice, new { @readonly = "readonly", @class = "inputNumberField" ,@Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(@Model.GrossPrice)})</td>
                    </tr>

                    <tr>
                        <td style="width: 239px">&nbsp;</td>
                        <td style="width: 9px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 164px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <table width="95%" height="85" border="0" align="center">

                    <tr>
                        <td>
                            <div align="center">

                                <input id="BtnSave" type="button" name="BtnSave" value=" Submit " class="button" need-confirm="true">
                                &nbsp;&nbsp; 
                                      <input id="BtnCancel"  type="button" name="BtnCancel" class="btsub" value=" Cancel ">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="center"></div>
                        </td>
                    </tr>
                </table>
     
                @Html.HiddenFor(x => x.UpdateMode);
                @Html.HiddenFor(x => x.HeaderID);
                @Html.HiddenFor(x => x.PurcheseID);
                @Html.HiddenFor(x => x.TransactionID);
            }
            <br>
        </td>
    </tr>
</table>
